<#assign base=request.contextPath />
<!DOCTYPE html>
<div class="row">
	<div class="col-md-12 col-sm-12 col-xs-12">
		<div class="x_panel">
			<div class="x_title">
				<h2>管理员编辑 <small></small></h2>
				<div class="clearfix"></div>
			</div>
			<div class="x_content">
				<br/>
				<form id="postForm" data-parsley-validate class="form-horizontal form-label-left">
					<input type="hidden" id="id" name="id" value="${((obj.id)?c)!'' }">
		            <input type="hidden" name="createTime" value="${(obj.createTime)!.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="updateTime" value="${.now?string['yyyy-MM-dd HH:mm:ss']}">
		            <input type="hidden" name="creator" value="${(obj.creator)!admin.userName}">
					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">用户名 <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<input type="text" id="userName" name="userName" value="${(obj.userName)!''}" class="form-control col-md-7 col-xs-12">
                        </div>
					</div>
 					<div class="form-group">
						<label class="control-label col-md-3 col-sm-3 col-xs-12" for="first-name">所属角色<span class="required"></span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                        	<select id="roleId" name="role.id" class="form-control select2">
	                        	<#list roleList as role>
	                        	<option <#if obj ??><#if ((obj.role.id) == (role.id))>selected="selected"</#if></#if>value="${role.id?c}">${role.roleName}</option>
	                        	</#list>
	                    	</select>
                        </div>
					</div>
					<div class="ln_solid"></div>
					<div class="form-group">
						<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
							<button type="button" class="btn btn-success" id="submit">保存</button>
							<button type="button" class="btn btn-primary" id="goBack">返回</button>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript">
$(function() {
	//select2
	$(".select2").select2({width: "100%"});
	// /select2

	$("#goBack").click(function() {
		$("#main_content").load('${base}/gx/sysAdmin/list');	        
    });
	
	$("#submit").click(function() {
	
		var userName = $.trim($("#userName").val());
    	if(userName==""){
    		swal("请输入用户名");
            return;
    	}
        var url = "${base}/gx/sysAdmin/save";
        $.post(url, $("#postForm").serialize(), function(data) {
            if (data.flag) {
            	swal(data.msg, "", "success");
                $("#main_content").load('${base}/gx/sysAdmin/list');
            }else{
            	swal(data.msg, "", "error");
            }
        });
    });
});
</script>